package list;

import java.util.Collections;
import java.util.Vector;

//类似ArrayList
//支持线程同步，某一时刻只有一个线程能写vector，访问速度较慢
public class VectorDemo {
    public static void main(String[] args) {
//      1.初始默认容量为10
        Vector v1 = new Vector();
//      2.指定容量
        Vector v2 = new Vector(50);
//      3.指定初始容量为3，每次增加为2
        Vector v3 = new Vector(3,2);
//      4.将一个集合添加进去
        Vector v4 = new Vector(Collections.emptyList());
        System.out.println("Initial size: " + v3.size());
        System.out.println("Initial capacity: " + v3.capacity());
        //因为每次增量是2如果不满足两个也会增加
        v3.addElement(new Integer(1));
        v3.addElement(new Integer(2));
        v3.addElement(new Integer(3));
        v3.addElement(new Integer(4));
        System.out.println("Capacity after four additions: " +
                v3.capacity());
        v3.addElement(new Double(6.08));
        v3.addElement(new Integer(7));
        System.out.println("Current capacity: " +
                v3.capacity());
        v3.addElement(new Integer(11));
        v3.addElement(new Integer(12));
        System.out.println("First element: " +
                v3.firstElement());
        System.out.println("Last element: " +
                v3.lastElement());
        if(v3.contains(new Integer(3)))
            System.out.println("Vector contains 3.");
    }
}
